// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 * TEMPLATE:    SpringServiceImpl.vsl in andromda-spring cartridge
 * MODEL CLASS: AndroMDAModel::JR Appointment Service::com.systemsjr.jrappointment::customer::service::CustomerService
 * STEREOTYPE:  Service
 */
package com.systemsjr.jrappointment.customer.service;

import com.systemsjr.jrappointment.customer.Customer;
import com.systemsjr.jrappointment.customer.CustomerDao;
import com.systemsjr.jrappointment.customer.vo.CustomerSearchCriteria;
import com.systemsjr.jrappointment.customer.vo.CustomerVO;

import java.util.Collection;
import java.util.List;

/**
 * @see com.systemsjr.jrappointment.customer.service.CustomerService
 */
public class CustomerServiceImpl
    extends CustomerServiceBase
{

    /**
     * @see com.systemsjr.jrappointment.customer.service.CustomerService#loadAll()
     */
    protected  Collection<CustomerVO> handleLoadAll()
        throws Exception
    {
    	return (Collection<CustomerVO>) getCustomerDao().loadAll(CustomerDao.TRANSFORM_CUSTOMERVO);
    }

    /**
     * @see com.systemsjr.jrappointment.customer.service.CustomerService#save(CustomerVO)
     */
    protected  CustomerVO handleSave(CustomerVO customerVO)
        throws Exception
    {
    	Customer customer = getCustomerDao().customerVOToEntity(customerVO);
    	
    	if(customerVO.getId() == null){
    		customer = getCustomerDao().create(customer);
    	} else{
    		getCustomerDao().update(customer);
    	}
    	
    	return getCustomerDao().toCustomerVO(customer);
    }

    /**
     * @see com.systemsjr.jrappointment.customer.service.CustomerService#delete(CustomerVO)
     */
    protected  void handleDelete(CustomerVO customerVO)
        throws Exception
    {
    	
    	if(customerVO.getId() != null){
    		getCustomerDao().remove(customerVO.getId());
    	}
    	
    }

    /**
     * @see com.systemsjr.jrappointment.customer.service.CustomerService#search(CustomerSearchCriteria)
     */
    protected  Collection<CustomerVO> handleSearch(CustomerSearchCriteria searchCriteria)
        throws Exception
    {
    	return getCustomerDao().toCustomerVOCollection(getCustomerDao().findByCriteria(searchCriteria));
    }

}